package com.eqdd.yiqidian.utils;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.InviteCareerListResultBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.select.MultiSelectBuilder;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

/**
 * @author吕志豪 .
 * @date 18-1-6  上午11:22.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class SelectUtil {
    public static void selectPost(BaseActivity baseActivity, boolean isDepart, int requestCode, ArrayList<InviteCareerListResultBean> selectedBean) {
        OkGo.<HttpResult<List<InviteCareerListResultBean>>>post(HttpConfig.BASE_URL + HttpConfig.SELECT_CAREER_ALL)
                .params("comid", AppConstent.user.getCompanyId())
                .params("userGuid", AppConstent.user.getGuid())
                .execute(new DialogCallBack<HttpResult<List<InviteCareerListResultBean>>>(baseActivity) {

                    @Override
                    public void onSuccess(Response<HttpResult<List<InviteCareerListResultBean>>> response) {
                        HttpResult<List<InviteCareerListResultBean>> httpResult = response.body();
                        if (httpResult.getStatus() == 200) {
                            if (isDepart) {
                                for (int i = httpResult.getItems().size() - 1; i >= 0; i--) {
                                    if (httpResult.getItems().get(i).getDeid() != AppConstent.user.getDepartId()) {
                                        httpResult.getItems().remove(i);
                                    }
                                }
                            }
                            new MultiSelectBuilder(R.layout.list_item_06)
                                    .setAllDatas(httpResult.getItems())
                                    .setCompareField("id")
                                    .setMinSelectNum(1)
                                    .setSelectDatas(selectedBean)
                                    .setMode(MultiSelectBuilder.MULTI_MODE)
                                    .build(baseActivity, requestCode, (data, inject) -> {
                                        InviteCareerListResultBean bean = (InviteCareerListResultBean) data;
                                        inject.text(R.id.tv_upper_content, bean.getName())
                                                .text(R.id.tv_down_content, bean.getDename());
                                    });
                        }
                    }
                });

    }

    public static void selectPostFromDepart(BaseActivity baseActivity,ArrayList<InviteCareerListResultBean> selectedBean) {
        selectPost(baseActivity, true, Config.SELECT_POST_FROM_DEPART,selectedBean);
    }

    public static void selectPostFromCom(BaseActivity baseActivity,ArrayList<InviteCareerListResultBean> selectedBean) {
        selectPost(baseActivity, false, Config.SELECT_POST_FROM_COM,selectedBean);
    }
}
